package com.xls.base.config;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger2Config {

    //@Bean
    //public Docket webApiConfig(){
    //    return new Docket(DocumentationType.SWAGGER_2)
    //            .groupName("webApi")
    //            .apiInfo(webApiInfo())
    //            .select()
    //            .paths(Predicates.not(PathSelectors.regex("/error.*")))
    //            .build();
    //}

    @Bean("api")
    public Docket aclApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("aclAPi")
                .apiInfo(apiInfo("权限管理", "权限管理接口"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.xls.aclservice.controller"))
                //请求路径过滤
                //.paths(PathSelectors.any())
                .paths(Predicates.not(PathSelectors.regex("/error.*")))//错误路径不监控
                .paths(PathSelectors.regex("/.*"))// 对根下所有路径进行监控
                .build();
    }

    @Bean
    public Docket minioApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("minioAPi")
                .apiInfo(apiInfo("文件上传", "文件上传接口"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.xls.minio.controller"))
                //请求路径过滤
                //.paths(PathSelectors.any())
                .paths(Predicates.not(PathSelectors.regex("/error.*")))//错误路径不监控
                .paths(PathSelectors.regex("/.*"))// 对根下所有路径进行监控
                .build();
    }

    @Bean
    public Docket roomApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("roomAPi")
                .apiInfo(apiInfo("宿舍管理", "宿舍管理接口"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.xls.dormitoryservice.controller"))
                //请求路径过滤
                //.paths(PathSelectors.any())
                .paths(Predicates.not(PathSelectors.regex("/error.*")))//错误路径不监控
                .paths(PathSelectors.regex("/.*"))// 对根下所有路径进行监控
                .build();
    }

    public ApiInfo apiInfo(String title, String description){
        return new ApiInfoBuilder()
                .title(title)
                .description(description)
                .version("1.0")
                .contact(new Contact("xls", "https://Xls-Ah.github.io", "1285544891@qq.com"))
                .build();
    }

    //
    //@Bean
    //public ApiInfo webApiInfo() {
    //    return new ApiInfoBuilder()
    //            .title("网站的API文档")
    //            //.description("SpringBoot整合Swagger")
    //            .version("1.0")
    //            .contact(new Contact("xls", "https://Xls-Ah.github.io", "xls@163.com"))
    //            .build();
    //}
    //
    //
    //@Bean
    //public ApiInfo adminApiInfo() {
    //    return new ApiInfoBuilder()
    //            .title("后台管理系统API文档")
    //            .version("1.0")
    //            .contact(new Contact("xls", "https://Xls-Ah.github.io", "xls@163.com"))
    //            .build();
    //}

}
